package com.drug.mingkang.service.impl;
import com.drug.mingkang.model.Inform;
import com.drug.mingkang.mapper.InformMapper;
import com.drug.mingkang.model.Record;
import com.drug.mingkang.service.InformService;
import com.drug.mingkang.service.RecordService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * 通知公告(Inform)表服务实现类
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:14
 */
@Service("informService")
public class InformServiceImpl implements InformService {
    @Resource
    private InformMapper informMapper;


    @Resource
    private RecordService  recordService;
    /**
     * 通过ID查询单条数据
     *
     * @param informId 主键
     * @return 实例对象
     */
    @Override
    public Inform queryById(String informId) {
        return this.informMapper.queryById(informId);
    }

    @Override
    public Inform selectById(String informId) {
        return this.informMapper.selectById(informId);
    }

    /**
     * 查询多条数据
     *
     * @param inform
     * @return 对象列表
     */
    @Override
    public List<Inform> queryAllByLimit(Inform  inform , String CompanyId) {
        return this.informMapper.queryAllByLimit(inform , CompanyId);
    }

    /**
     * 新增数据   发布时给记录表增加一条数据
     * @param inform 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Inform inform) {
       int  rows =   this.informMapper.insert(inform);
        Record  record = new Record();
        record.setRecordId(UUID.randomUUID().toString());
        record.setInformId(inform.getInformId());
        record.setImmName(inform.getImmName());
        record.setInformContent(inform.getInformContent());
        record.setInformTime(inform.getInformTime());
        record.setOper(inform.getOper());
        record.setInformName(inform.getInformName());
        record.setSort(inform.getSort());
        record.setOptime(inform.getOptime());
        record.setRemark(inform.getRemark());
        recordService.insert(record);
        return rows;
    }

    /**
     * 修改数据
     *
     * @param inform 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Inform inform) {
        int rows =  this.informMapper.update(inform);
        return  rows;
    }

    /**
     * 通过主键删除数据
     * @param informId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(String informId) {
        int rows = informMapper.deleteById(informId);
        return rows;
    }

    @Override
    public int selectCount(Inform inform) {
        return this.informMapper.selectCount(inform);
    }

    @Override
    public List<Inform> selectIname() {
        return this.informMapper.selectIname();
    }

    @Override
    public List<Inform> queryAllInform() {
        return  this.informMapper.queryAllInform();
    }
}